import httpUtils from './httpUtils.js'
import ui from './ui.js'
// 获取home页面所有数据的方法
function getHomeData(_this) {
  // console.log(data)
  let obj = {
    method: "GET",
    showLoading: true,
    url: `/home/getHomeData`,
  }
  httpUtils.request(obj).then(res => {
    res.data.forEach(item => {
      switch (item.name) {
        case 'SwiperData':
          _this.swiperdata = item.data
          break
        case "NavListData":
          _this.navList = item.data
          break
        case "PopTeacherData":
          _this.popTeacher = item.data
          break
        case "RecentLearnData":
          _this.recentLearn = item.data
      }
    })
  })
  .catch(err => {
    console.log(err)
  });
};
// 分类点击事件
function navClickHandler(e) {
  try {
    uni.setStorageSync('cate_id', e.target.dataset.cate_id);
  } catch (e) {
    console.log(e);
  }
  uni.switchTab({
    url: `/pages/cate/cate?cate_id=123`
  })
}
// 课程点击事件
function toClass(id) {
  uni.navigateTo({
    url: `/subpackage/class_detail/class_detail?class_id=${id}`
  })
}
// 热门教师模块点击事件
function toTeacher(e) {
  uni.navigateTo({
    url: `/subpackage/teacher/teacher?teacher_id=${e.target.dataset.teacher_id}`,
  })
}
// 最近学习加载更多
function getMore() {
  this.recentLearnNum = this.recentLearnNum + 4
  console.log(this.recentLearn);
  uni.showToast({
    duration: 1000,
    icon: 'loading',
    title: '正在加载'
  })
}

module.exports = {
  getHomeData,
  navClickHandler,
  toClass,
  toTeacher,
  getMore
}
